<?php

$typelist = '';
$typerows = Db::getRows('*', 'type', 'menu=4');
foreach ($typerows as $typerow) {
    $typelist .= '<option value="' . $typerow['id'] . '">' . $typerow['name'] . '</option>';
}

if (Http::isPost()) {
    $type = $_POST['typelist'];
    $title = Form::input('title', 'ne');
    $intro = Form::input('intro');
    $content = Form::input('content');
    $title2 = Form::input('title2', 'ne');
    $intro2 = Form::input('intro2');
    $content2 = Form::input('ct2');
    $posteddate = date('H:i d-m-Y');
    $img = '';
    if (Form::isValid()) {
        $curpath = $_SERVER['DOCUMENT_ROOT'] . str_replace('/admin', '/upload/', baseUrl());

        if ($_FILES["file"]["error"] > 0 && $_FILES["file"]["error"] != '4') {
            Js::alert("Có lổi: " . $_FILES["file"]["error"] . "<br />");
        } else if ($_FILES["file"]["error"] == '4') {
            $eval = eval(Db::insert('article', array_merge(array('id', 'nation', 'level'))));
            if (mysql_affected_rows() > 0) {
                Js::alert(fl('success_insert'));
                Js::GoUrl(baseUrl() . '/dichvuList');
                exit();
            }
        } else {
            $upload = Http::UploadImage('file', str_replace('//', '/', $curpath), '', $img);
            if ($upload === '') {
                $eval = eval(Db::insert('article', array_merge(array('id', 'nation', 'level'))));
                if (mysql_affected_rows() > 0) {
                    Js::alert(fl('success_insert'));
                    Js::GoUrl(baseUrl() . '/dichvuList');
                    exit();
                }
            } else {
                Js::alert($upload);
            }
        }
    }
}
?>
